import 'package:flutter/material.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/pages/game/game_detail/game_detail_logic.dart';
import 'package:flutter_09_game/pages/game/game_detail/game_detail_page/game_detail_page_logic.dart';
import 'package:flutter_09_game/utils/extensions/num_ext.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class WidgetLimitBetTop extends StatelessWidget {
  // const WidgetLimitBetTop({super.key});
  const WidgetLimitBetTop(
      {super.key,
      required this.gameLogic,
      // required this.logic,
      this.isPage = true});
  final bool isPage;
  final GameDetailLogic gameLogic;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Obx(() {
              return _buildLeftSection();
            }),
            12.verticalSpaceFromWidth,
            const Spacer(),

            12.horizontalSpace,
            // 右侧区域：操作按钮
            Obx(() {
              return GestureDetector(
                onTap: () {
                  gameLogic.toggleSoundEnabled();
                },
                child: AutoImage(
                  gameLogic.soundRx.value
                      ? Assets.gameVolumeOpen
                      : Assets.gameVolumeClose,
                  width: 32.w,
                ),
              );
            }),
            12.horizontalSpace,
            GestureDetector(
              onTap: () {
                gameLogic.showRuleSheet();
              },
              child: AutoImage(
                Assets.gameRule,
                width: 32.w,
              ),
            ),
          ],
        ),
        Obx(() {
          return Text(
            getLimitMinMax(),
            //   '${LocaleKeys.singleLimit.tr}: ${gameLogic.gameRoundRx.value.betLimit?.pageBetLimitForUSDTConfigKey?.min.formatLimiting()}-${gameLogic.gameRoundRx.value.betLimit?.pageBetLimitForUSDTConfigKey?.max.formatLimiting()} USDT / ${gameLogic.gameRoundRx.value.betLimit?.pageBetLimitForTRXConfigKey?.min.formatLimiting()}-${gameLogic.gameRoundRx.value.betLimit?.pageBetLimitForTRXConfigKey?.max.formatLimiting()} TRX',
            style: TextStyle(
              fontSize: 12.sp,
              fontWeight: FontWeight.w400,
              color: AppColor.textPrimary.withOpacity(0.7), // 白色半透明
            ),
          );
        }),
      ]),
    );
  }

  /// 构建左侧区域
  Widget _buildLeftSection() {
    return Row(
      children: [
        // 游戏标题
        Text(
          gameLogic.name,
          style: TextStyle(
            fontSize: 16.sp,
            fontWeight: FontWeight.w600,
            color: AppColor.textPrimary.withOpacity(0.94), // 白色
          ),
        ),
        8.horizontalSpace,
        // 倍数标签
        Container(
          padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 2.w),
          decoration: BoxDecoration(
            color: AppColor.primary.withOpacity(0.3), // 蓝色半透明背景
            borderRadius: BorderRadius.circular(2.w),
          ),
          child: Text(
            '${gameLogic.gameRoundRx.value.latest?.game?.winRate ?? 1} X',
            style: TextStyle(
              fontSize: 10.sp,
              fontWeight: FontWeight.w600,
              color: AppColor.primary, // 蓝色文字
            ),
          ),
        ),
        // 8.horizontalSpace,
        // // 用户统计
        // Container(
        //   padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 3.w)
        //       .copyWith(right: 6.w),
        //   decoration: BoxDecoration(
        //     color: Colors.black.withOpacity(0.3), // 半透明黑色背景
        //     borderRadius: BorderRadius.circular(100.w),
        //   ),
        //   child: Row(
        //     mainAxisSize: MainAxisSize.min,
        //     children: [
        //       // 在线状态指示器
        //       Container(
        //         width: 12.w,
        //         height: 12.w,
        //         decoration: BoxDecoration(
        //           color: AppColor.homePrizePoolBgIndicator
        //               .withOpacity(0.12), // 绿色半透明背景
        //           shape: BoxShape.circle,
        //         ),
        //         child: Center(
        //           child: Container(
        //             width: 6.w,
        //             height: 6.w,
        //             decoration: const BoxDecoration(
        //               color: AppColor.homePrizePoolIndicator, // 绿色圆点
        //               shape: BoxShape.circle,
        //             ),
        //           ),
        //         ),
        //       ),
        //       2.horizontalSpace,
        //       Text(
        //         (gameLogic.gameRoundRx.value.userCount ?? 0).toString(),
        //         style: TextStyle(
        //           fontSize: 10.sp,
        //           fontWeight: FontWeight.w600,
        //           color: AppColor.textPrimary.withOpacity(0.7), // 白色半透明
        //         ),
        //       ),
        //       2.horizontalSpace,
        //       // 用户图标
        //       AutoImage(
        //         Assets.gameUserTag,
        //         width: 12.w,
        //         height: 12.w,
        //       ),
        //     ],
        //   ),
        // )
      ],
    );
  }

  String getLimitMinMax() {
    if (isPage) {
      return '${LocaleKeys.singleLimit.tr}: ${gameLogic.gameRoundRx.value.betLimit?.pageBetLimitForUSDTConfigKey?.min.formatWallet()}-${gameLogic.gameRoundRx.value.betLimit?.pageBetLimitForUSDTConfigKey?.max.formatWallet()} USDT / ${gameLogic.gameRoundRx.value.betLimit?.pageBetLimitForTRXConfigKey?.min.formatWallet()}-${gameLogic.gameRoundRx.value.betLimit?.pageBetLimitForTRXConfigKey?.max.formatWallet()} TRX';
    } else {
      // ${LocaleKeys.transferLimit.tr}: ${gameLogic.gameRoundRx.value.betLimit?.transferBetLimitForUSDTConfigKey?.min.formatLimiting()}-${gameLogic.gameRoundRx.value.betLimit?.transferBetLimitForUSDTConfigKey?.max.formatLimiting()} USDT /
    return '${LocaleKeys.transferLimit.tr}: ${gameLogic.gameRoundRx.value.betLimit?.transferBetLimitForTRXConfigKey?.min.formatWallet()}-${gameLogic.gameRoundRx.value.betLimit?.transferBetLimitForTRXConfigKey?.max.formatWallet()} TRX';
    }
  }
}
